package br.com.exemplo.swing;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ExemploJFileChooser {

	public static void main(String[] args) {
		JFrame janela = new JFrame("Titulo da Janela");

		JPanel painel = new JPanel();
		janela.add(painel);

		JButton botao = new JButton("Arquivos");
		painel.add(botao);
		
		botao.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				JFileChooser fileChooser = new JFileChooser();
				int retorno = fileChooser.showOpenDialog(null);
				if (retorno == JFileChooser.APPROVE_OPTION) {
					File file = fileChooser.getSelectedFile();
					// Arquivo selecionado
				} else {
					// Usuario cancelou a operacao
				}
			}
		});


		janela.setSize(325, 100);
		janela.setVisible(true);
		janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

}
